# -*- utf-8 -*-
# @Time: 2021/7/29 10:37
# @Author: CACode
import re
import random

from django.core.cache import cache

from config import OutTime


def verify_mobile(phone):
    ret = re.match(r"1[358]\d{9}", str(phone))
    return ret is not None


def get_ver_code(redis_key):
    code = random.randint(100000, 999999)
    # 五分钟失效
    # cache.set(redis_key, code, 60 * 5)
    cache.set(redis_key, code, OutTime.SMS_VER_CODE_OUT_TIME)
    return code


def get_reset_code(redis_key):
    code = random.randint(100000, 999999)
    # 五分钟失效
    cache.set(redis_key, code, OutTime.RESET_CODE_OUT_TIME)
    return code
